
<div class="card card-table mb-1">
	<div class="card-body page-body">
		<div class="row align-items-center oper-list">
			<div class="col-3">
			#if(session.hasOper(Permissions.fund_flow_expenses_export))
			<div class="btn-group" role="group" aria-label="Button group with nested dropdown">
			  <button type="button" class="btn btn-sm btn-outline-secondary" onclick="flowExpenses.export();">导出</button>
			  <div class="btn-group" role="group">
			    <button type="button" class="btn btn-sm btn-outline-secondary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false"></button>
			    <ul class="dropdown-menu">
			      <li><a class="dropdown-item" href="javascript:void(0);" onclick="flowExpenses.exportLog();">导出记录</a></li>
			    </ul>
			  </div>
			</div>
			#end
			</div>
			<div class="col">
			#if(page.totalPage > 1)
			<div class="float-end">#@paginate(page.pageNumber, page.totalPage, "")</div>
			#end
				<div class="float-end me-3 mt-1">
					#if(orderAuditFlag)
					#if(session.hasOper(Permissions.fund_flow_expenses_audit))
					<input class="form-check-input" type="checkbox" name="show_audit_flag" id="flowExpenses_show_audit_flag" #if(showAuditFlag) checked #end onclick="flowExpenses.list();"> 
					<label class="form-check-label" for="flowExpenses_show_audit_flag"> 待审核单据</label>
					&nbsp;&nbsp;&nbsp;
					#end
					#end
					<input class="form-check-input" type="checkbox" name="hide_disable_flag" id="flowExpenses_hide_disable_flag" #if(hideDisableFlag) checked #end onclick="flowExpenses.list();"> 
					<label class="form-check-label" for="flowExpenses_hide_disable_flag"> 隐藏作废单据</label>
					</div>
			</div>
			
		</div>
	</div>
</div>

<table class="table table-hover table-bordered bg-white">
	<thead>
		<tr class="table-header">
			<th>单据编号</th>
			<th>销售日期</th>
			<th>支出项目</th>
			<th>支出金额</th>
			<th>经办人</th>
			<th>单据状态</th>
			<th>备注</th>
			<th style="width: 10%">操作</th>
		</tr>
	</thead>
	<tbody class="table-row" id="flowExpenses-list">
		#for (x : page.getList())
		<tr data-id="#(x.id)" id="flowExpenses-data-#(x.id)" #if(x.order_status == OrderStatusEnum.disable.value) class="disable-order"  #end>
			<td>#(x.order_code)</td>
			<td>#date(x.order_time, "yyyy-MM-dd")</td>
			<td>#(x.fundType.name??)</td>
			<td><span class="fw-bold text-secondary">#number(x.amount, "#.##")</span> </td>
			<td>#(x.handler.real_name??)</td>
			<td>
			#if(x.order_status == OrderStatusEnum.disable.value)
			<span class="text-decoration-line-through">已作废</span>
			#elseif(x.audit_status == AuditStatusEnum.waiting.value)
			<span class="badge bg-danger">待审核</span>
			#elseif(x.audit_status == AuditStatusEnum.reject.value)
			<span class="badge bg-warning" data-bs-toggle="tooltip" data-bs-placement="top" title="#(x.audit_desc)">审核拒绝</span>
			#elseif(x.audit_status == AuditStatusEnum.pass.value)
			<span class="badge bg-success">已完成</span>
			#end
			</td>
			<td>#(x.remark)</td>
			<td>
				#if(x.order_status == OrderStatusEnum.disable.value)
				<span class="text-decoration-line-through">已作废</span>
				#else
				#if(x.audit_status == AuditStatusEnum.waiting.value)
				#if(session.hasOper(Permissions.fund_flow_expenses_audit))
				<button type="button" class="btn btn-sm sm-more btn-outline-primary" onclick="flowExpenses.audit(#(x.id));">审核</button> 
				#end
				#end
				#if(!orderAuditFlag || (orderAuditFlag && (x.audit_status != AuditStatusEnum.pass.value || session.hasOper(Permissions.fund_flow_expenses_audit))))
				#if(session.hasOper(Permissions.fund_flow_expenses_update))
				<button type="button" class="btn btn-sm sm-more btn-outline-primary" onclick="flowExpenses.edit(#(x.id));">修改</button> 
				#end 
				#end
				#end 
			</td>
		</tr>
		#end

	</tbody>
</table>

<script type="application/javascript">
	
$(function() {
	// 初始化bootstrap相关组件
	common.initBootstrap();
	// 滚动表头处理
	common.tableFixedWidth();
	common.tableFixed();
	$(".main").scroll(function() {
		common.tableFixed();
	});
	$("#flowExpenses_pageNumber").val(#(page.pageNumber));
	
	$("#flowExpenses-list tr").on("dblclick", function() {
		flowExpenses.show($(this).attr("data-id"));
	});
	
});

flowExpenses.show = function(id) {
	beekit.offcanvas("/fund/flow/expenses/show?id="+id);
};


flowExpenses.edit = function(id) {
	beekit.offcanvasClose();
	beekit.modal("/fund/flow/expenses/edit?id="+id);
};

flowExpenses.audit = function(id) {
	beekit.offcanvasClose();
	beekit.modal("/fund/flow/expenses/audit?id="+id);
};

flowExpenses.disable = function(id) {
	beekit.confirmByUrl("/fund/flow/expenses/disable", {"id":id}, "确认要作废此支出单据吗？", function(ret) {
		common.processRequestResult(ret, function(ret) {
			beekit.msg(ret);
			beekit.offcanvasClose();
			flowExpenses.list(id);
		});
	});
};

flowExpenses.delete = function(id) {
	beekit.focusColor("goodsInfo-data-"+id);
	beekit.confirmByUrl("/fund/flow/expenses/delete", {"id":id}, "确认要删除此支出单据吗？", function(ret) {
		beekit.msg(ret);
		beekit.offcanvasClose();
		flowExpenses.list();
	});
};


flowExpenses.export = function() {
	var showAuditFlag = $("#flowExpenses_show_audit_flag").prop("checked");
	if(typeof(showAuditFlag) == 'undefined') {
		showAuditFlag = false;
	}
	var hideDisableFlag = $("#flowExpenses_hide_disable_flag").prop("checked");
	if(typeof(hideDisableFlag) == 'undefined') {
		hideDisableFlag = true;
	}
	var hidePayFlag = $("#flowExpenses_hide_pay_flag").prop("checked");
	if(typeof(hidePayFlag) == 'undefined') {
		hidePayFlag = false;
	}
	beekit.confirmByUrl("/fund/flow/expenses/export?hide_disable_flag="+hideDisableFlag+"&show_audit_flag="+showAuditFlag+"&hide_pay_flag="+hidePayFlag, $("#flowExpenses-search-form").serialize(), "确定要导出单据吗？", function(ret) {
		flowExpenses.exportLog(ret.targetId);
	});
}

flowExpenses.exportLog = function(targetId) {
	beekit.modal("/export/log/?targetId="+targetId);
}


</script>
